Copyright ã1992 by Allegheny College

PetriDish

INHERITS FROM	View : Responder : Object

DECLARED IN	PetriDish.h

WRITTEN BY	Charles G. Fleming

CLASS DESCRIPTION

PetriDish is a view that simulates the Biological laboratory equipment by the same name.  There are methods for setting the radius of the petri dish, as well as, the color of the agar it contains.  Microorganisms  normally grown in petri dishes will be represented in a PetriDish view by dots.  Consequently, there are also methods to set the radii color and number of  these dots.  Since it is important to be able to easily count the size of the population  growing in a petri dish, there is a method for placing a resizable grid over the petri dish.    To further simplify the task of counting the spots displayed in the petri dish, one can click the mouse on the petri dish once for each spot.   After each mouse click, the total number of clicks that have occurred since the last resetClickCount message was received will be displayed in the text field clickCountTextField. 

 For ease of use, the PetriDish class has been "palette-ised".  If the PetriDishPalette is loaded into Interface Builder, petri dishes can be instantiated graphically and all of their attributes can be set with the accompanying petri dish inspector.

Under normal circumstances, one sets the attributes of a petri dish, except for the number of spots that will appear.  The petri dish with its spots can then be displayed by sending a PetriDish object a      
 drawPetriDishWithSpots:(int)spots message.  If an overlaying grid is desired, send a 
 turnGridOn:(BOOL)flag withSpacing:(float)spacing message with a value of YES for the argument flag and the desired spacing (in centimeters) for the argument spacing.   

INSTANCE VARIABLES

Inherited from Object	Class	isa;

Inherited from Responder	id	nextResponder;

Inherited from View	                NXRect	                     frame;
	NXRect	bounds;
	id	superview;
	id	subviews;
	id	window;
	struct __vFlags            	vFlags;

Declared in PetriDish	id	petriDishNXImage
	id	spotsNXImage
	id	gridNXImage
	id	spotNXImage
	id	inspector
	id	clickCountTextField
	BOOL	gridState
	BOOL	okButtonPushed
	float	gridSpacing
	float	petriDishRadius
	float	spotRadius
	float	agarRadius
	float	dotRadius
	float	gridDelta
	float	petriRed
	float	petriGreen
	float 	petriBlue
	float	spotRed
	float	spotGreen
	float	spotBlue
	int	numSpots
	int	clicks
	NXColor	agarColor
	NXColor	spotColor
	NXSize	spotNXImageSize	

petriDishNXImage 	An NXImage into which a petri dish to be displayed will be drawn.

spotsNXImage 	An NXImage into which all of the spots to be displayed will be drawn.

gridNXImage 	An NXImage into which the overlaying grid to be displayed will be drawn.

spotNXImage 	An NXImage into which a single spot will be drawn.

inspector 	The inspector used by Interface Builder for the petri dish.

		clickCountTextField		      The contents of the instance variable clicks can be displayed in this text field.

gridState 	YES if the grid overlays the petri dish, NO otherwise.

okButtonPushed 	YES if the OK button was pushed in the inspector.

gridSpacing 	The distance (in centimeters) between parallel grid lines, horizontal or vertical.

petriDishRadius 	The radius of the petri dish (in centimeters).

spotRadius 	The radius of each spot (in millimeters).

agarRadius 	The radius of the petri dish (in pixels).

dotRadius	The radius of each spot (in pixels).

gridDelta 	The distance (in pixels) between parallel grid lines, horizontal or vertical.

petriRed 	The amount of red in the petri dish's agar.

petriGreen 	The amount of green in the petri dish's agar.

petriBlue 	The amount of blue in the petri dish's agar.

spotRed 	The amount of red in each spot.

spotGreen 	The amount of green in each spot.

spotBlue 	The amount of blue in each spot.

numSpots 	The number of spots displayed.

clicks	The current number of clicks that have been done over the petri dish since resetClickCount: has been sent to the petri dish.

agarColor 	The color of the agar.

spotColor	The color of each spot.	

spotNXImageSize	The size of the NXImage into which a single spot will be drawn.

METHOD TYPES

Initializing petri dish objects	- initFrame:

Petri dish attributes	- setAgarRadius: 
- setAgarColor: 
- agarColor
- petriDishRadius
- agarColor

Spot attributes	- setSpotColor: 
- setSpotRadius: 
- setNumSpots: 
- numSpots
- spotRadius
- spotColor

Counting spots	- resetClickCount: 
	- clickCount: 
	- mouseDown: 

Grid attributes	- turnGridOn: withSpacing:
- gridSpacing 
- gridState 

Displaying the petri dish	- drawSelf:: 
- drawPetriDishWithSpots: 

Drawing in NXImages	- drawSpotsInNXImage:

Interacting with the inspector	- okPushed:
- setInspector:

Archiving	- awake
- read: 
- write:

INSTANCE METHODS

			agarColor
- (NXColor)agarColor

Returns the color of the agar in the petri dish. 

			awake
- awake

Invoked after unarchiving to allow the petri dish to perform additional initialization.  Returns self. 

clickCount
- (int)clickCount

Returns number of mouse clicks (which is held in the instance variable clicks) that have been done over the petri dish since that last resetClickCount: message was received.  Note that if  clickCountTextField has been set, the current click count is automatically displayed in that text field.

drawSelf::
- drawSelf:(NXRect *)rects :(int)count

Composites the three (possibly) NXImages which comprise the final image - petriDishNXImage, spotsNXImage and gridNXImage.  This method is normally NOT called directly or indirectly (by sending the display message).   Drawing should be done by sending the drawPetriDishWithSpots:  message.

drawPetriDishWithSpots:
- drawPetriDishWithSpots:(int)spots

Once the attributes of the petri dish and its spots have been set, this message should be sent to display the petri dish with spots spots. 

drawSpotsInNXImage:
- drawSpotsInNXImage:(int)spots

Draws the spots in an NXImage.  You normally do NOT send this message.  Does NOT redraw the petri dish. 

			gridSpacing	
- (float) gridSpacing

Returns the spacing between the rows or columns of the grid (in centimeters). 

gridState
- (float) gridState

Returns 1 if a grid is displayed, 0 otherwise. 

initFrame:
- initFrame:(NXRect *)frameRect

Initializes the petri dish. 

inspectorName
- (const char *)inspectorName

Returns the name of the inspector for the PetriDish class.  Used by Interface Builder. 

mouseDown:
- mouseDown:(NXEvent *)theEvent 

Each time the mouseDown: message is received, the clicks instance variable is incremented by one, and the value of clicks will be displayed in the text field clickCountTextField.

numSpots
- (int)numSpots

Returns the number of spots displayed in the petri dish. 

petriDishRadius
- (float)petriDishRadius

Returns radius of the petri dish (in centimeters). 

okPushed:
- okPushed:(BOOL)flag

This method is normally only called by the inspector in Interface Builder.  Sets the okButtonPushed instance variable. 

read:
- read:(NXTypedStream *)typedStream

Reads the PetriDish from the typed stream typedStream.  Returns self.

resetClickCount:
- resetClickCount:sender

Sets the instance variable clicks to zero and displays a zero in text field clickCountTextField.

resetCursorRects
- resetCursorRects

Sends the addCursorRect: cursor:  to self.  The current bounds of the petri dish become the cursor rectangle, and the cursor for this rectangle is a cross.

setAgarRadius:
- setAgarRadius:(float)radius

Sets the radius of the petri dish (which has the same radius as the agar it contains).  The argument radius is assumed to be in centimeters. Does NOT redraw the petri dish.

setAgarColor:
- setAgarColor:(NXColor)color

Sets the color of the petri dish (which has the same color as the agar it contains).  This method is normally called only by the petri dish inspector in Interface Builder.   Does NOT redraw the petri dish.

setFrame:
- setFrame:anObject

This method is called when the petri dish is resized in Interface Builder or when the OK button in the inspector is pushed.  If the petri dish is being resized, it is forced to be a square by using the smaller of the length and width for the size of the square.  

setInspector:
- setInspector:(const NXRect)frameRect

This method is normally only called by the inspector in Interface Builder.  Sets the inspector instance variable. 

setNumSpots:
- setNumSpots:(int)spots

Sets the number of spots that will appear in the petri dish.  This method is normally called only by the petri dish inspector in Interface Builder.   Does NOT redraw the petri dish.

setSpotColor:
- setSpotColor:(NXColor)color

Sets the color of the spots that will appear in the petri dish.  This method is normally called only by the petri dish inspector in Interface Builder.   Does NOT redraw the petri dish.

setSpotRadius:
- setSpotRadius:(float)radius

Sets the radius of the spots that will appear in the petri dish.  This method is normally called only by the petri dish inspector in Interface Builder.   Does NOT redraw the petri dish.

spotColor
- (NXColor)spotColor

Returns the color of each spot displayed in the petri dish. 

spotRadius
- (float)spotRadius

Returns radius of each spot (in millimeters).

turnGridOn:withSpacing:
- turnGridOn:(BOOL)flag withSpacing:(float)spacing

If flag is YES, a grid with spacing spacing will overlay the petri dish.  To change the size of the grid in a "zoom" fashion, send this message with a value of YES for flag, and the value of spacing obtained from a control, such as a slider.

write:
- write:(NXTypedStream *)typedStream

Writes the receiving PetriDish to the typed stream typedStream.  Returns self.